/**
 * May 14, 2014 1:09:38 PM
 */
package elitech.vietnam.copyweatherfashion.adapters;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.koushikdutta.urlimageviewhelper.UrlImageViewHelper;

import elitech.vietnam.copyweatherfashion.R;
import elitech.vietnam.copyweatherfashion.config.Const;
import elitech.vietnam.copyweatherfashion.entities.Comment;

/**
 * @author Cong
 *
 */
public class CommentAdapter extends ArrayAdapter<Comment> {

	public CommentAdapter(Context context, int resource, List<Comment> objects) {
		super(context, resource, objects);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View row = convertView;
		ViewHolder holder;
		
		if (null == row) {
			row = LayoutInflater.from(getContext()).inflate(R.layout.layout_comment, parent, false);
			
			holder = new ViewHolder();
			holder.mImgAvatar = (ImageView) row.findViewById(R.id.comment_imgAvatar);
			holder.mTxtName = (TextView) row.findViewById(R.id.comment_txtName);
			holder.mTxtContent = (TextView) row.findViewById(R.id.comment_txtContent);
			
			row.setTag(holder);
		} else
			holder = (ViewHolder) row.getTag();
		
		Comment mCmt = getItem(position);
		UrlImageViewHelper.setUrlDrawable(holder.mImgAvatar, Const.SERVER_IMAGE_THUMB_URL + mCmt.Image, R.drawable.avatar);
		holder.mTxtName.setText(mCmt.Name);
		holder.mTxtContent.setText(mCmt.Content);
		
		return row;
	}
	
	static class ViewHolder {
		TextView mTxtContent;
		ImageView mImgAvatar;
		TextView mTxtName;
	}
}
